fix(TC-2443): prevent redundant autocomplete API calls on Search page navigation#1116
Merged
carlosthe19916 merged 1 commit intoJul 1, 2026
Merged
Conversation
Signed-off-by: Carlos Feria <2582866+carlosthe19916@users.noreply.github.com>
Contributor
Reviewer's GuideRefactors SearchMenu’s search state synchronization and autocomplete gating to avoid redundant empty-query API calls and stale search flashes, and adds focused tests around the new behavior. Sequence diagram for SearchMenu autocomplete gating and state syncsequenceDiagram
actor User
participant SearchMenu
participant SbomSearchContext
participant useAllEntities
rect rgb(230,230,230)
User->>SearchMenu: onSubmitInput
SearchMenu->>SearchMenu: setIsSearchValueDirty(false)
SearchMenu->>SearchMenu: setIsAutocompleteOpen(false)
SearchMenu->>SearchMenu: submittedSearchValueRef.current = searchValue
SearchMenu->>SbomSearchContext: onChangeSearch(searchValue)
end
rect rgb(230,230,230)
SbomSearchContext-->>SearchMenu: appliedSearchValue
SearchMenu->>SearchMenu: useEffect([appliedSearchValue,isSearchValueDirty])
alt isSearchValueDirty is false and submittedSearchValueRef matches
SearchMenu->>SearchMenu: setSearchValue(appliedSearchValue)
SearchMenu->>SearchMenu: submittedSearchValueRef.current = null
else isSearchValueDirty is true
SearchMenu->>SearchMenu: [skip sync to avoid overwriting typing]
end
end
rect rgb(230,230,230)
User->>SearchMenu: type into input
SearchMenu->>SearchMenu: setSearchValue(newValue)
SearchMenu->>SearchMenu: setIsSearchValueDirty(true)
SearchMenu->>SearchMenu: setDebouncedSearchValue(searchValue)
SearchMenu->>SearchMenu: disableAutocomplete = !isSearchValueDirty || debouncedSearchValue.trim()==""
alt debouncedSearchValue non-empty and dirty
SearchMenu->>useAllEntities: useAllEntities(debouncedSearchValue, false)
else navigation/submit/clear or empty query
SearchMenu->>useAllEntities: useAllEntities(debouncedSearchValue, true)
end
end
rect rgb(230,230,230)
User->>SearchMenu: onClearSearchValue
SearchMenu->>SearchMenu: setSearchValue("")
SearchMenu->>SearchMenu: setIsSearchValueDirty(false)
SearchMenu->>SearchMenu: setIsAutocompleteOpen(false)
SearchMenu->>SearchMenu: submittedSearchValueRef.current = ""
SearchMenu->>SbomSearchContext: onChangeSearch("")
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1116 +/- ##
==========================================
+ Coverage 52.70% 53.05% +0.34%
==========================================
Files 270 270
Lines 5868 5884 +16
Branches 1839 1844 +5
==========================================
+ Hits 3093 3122 +29
+ Misses 2466 2459 -7
+ Partials 309 303 -6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
stanislavsemeniuk
approved these changes
Jul 1, 2026
Collaborator
Author
|
/backport |
Contributor
|
Successfully created backport PR for |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes TC-2443 — Navigating to the Search page after performing a search triggered redundant autocomplete API calls with an empty query, causing a brief confusing spinner popup and doubled API load.
Issues addressed
Redundant autocomplete calls on navigation — After searching (e.g. "quarkus") and navigating back to the Search page via the left nav,
useAllEntitiesfired 4 extra API requests (limit=5&q=) becauseisSearchValueDirtywas never reset when the search value was synced from external state (URL params).Stale value flash on clear/re-submit — After searching "something", clearing the input, and pressing Enter, the previous search term briefly flashed in the input. This happened because
onChangeSearch("")updates URL params asynchronously, so the context still held the old filter value for one render cycle.Unstable useEffect dependency — The sync useEffect depended on
sbomTableControls.filterState(an object recreated every render due to the non-memoized context chain). Replaced withappliedSearchValue, a stable string primitive that only changes when the actual URL filter param changes.Changes
SearchMenu.tsx:appliedSearchValueas a stable string fromfilterState— avoids the unstable object referenceuseEffectwithisSearchValueDirtyto prevent overwriting user input during typingsubmittedSearchValueRefto bridge the async gap between callingonChangeSearch()and the context reflecting the new value — prevents the stale flash!isSearchValueDirty || debouncedSearchValue.trim() === ""intodisableAutocomplete— prevents empty-query autocomplete during both navigation AND the debounce windowisSearchValueDirtyinonSubmitInputandonClearSearchValueonChangeSearch("")inonClearSearchValueSearchMenu.test.tsx(new):Before / After
Before fix
Notice the autocomplete generates 8 calls.
Screencast.From.2026-06-30.09-06-26.mp4
After fix
Notice the autocomplete generates 4 calls
Screencast.From.2026-06-30.09-05-29.mp4
Test plan
SearchMenu.test.tsx— 6 tests)🤖 Generated with Claude Code